package com.zhao;

import lombok.AllArgsConstructor;
import lombok.Data;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import javax.annotation.Resource;
import java.io.Serializable;

@SpringBootApplication
public class ApiDemoApplication  implements CommandLineRunner {

    //引入依赖模板
    @Resource
    private RocketMQTemplate rocketMQTemplate;

    //main函数，这里其实不需要 ....
    public static void main(String[] args) {
        SpringApplication.run(ApiDemoApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        //发送消息
        rocketMQTemplate.convertAndSend("test-topic-1", "Hello, World!");
        rocketMQTemplate.convertAndSend("test-topic-2",
                new OrderPaidEvent("orderId-0001", 88));
    }
}

@Data
@AllArgsConstructor
class OrderPaidEvent implements Serializable {
    private String orderId;
    private Integer paidMoney;
}

